package com.zhengtoudai.ui.adapter;

import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhengtoudai.R;
import com.zhengtoudai.global.Config;
import com.zhengtoudai.ui.bean.TransferModel;
import com.zhengtoudai.view.MyProgressBar;
import com.zhengtoudai.view.recyclerview.RecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：黑哥 on 2016/8/29 17:38
 */
public class TransferAdapter extends RecyclerViewAdapter<TransferAdapter.ViewHolder, TransferModel.TransferBean.TransferList> {
    private Fragment mFragment;
    public TransferAdapter(Fragment fragment){
        mFragment=fragment;
    }
    @Override
    public ViewHolder mOnCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_project, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void mOnBindViewHolder(ViewHolder holder, int position) {
        holder.mTvTitle.setText(data.get(position).getTransferTitle());
        holder.mTvYearRate.setText(data.get(position).getTransferInterestRate());
        holder.mTvProjectPriceTxt.setText("转让");
        holder.mTvProjectPrice.setText(data.get(position).getTransferMoney());
        int progress = 0;
        if(!TextUtils.isEmpty(data.get(position).getTransferStatus())){
            String status=data.get(position).getTransferStatus();
            int backgroundResId;
            String btnText;
            if (status.equals("0")){
                btnText="等待审核";
                backgroundResId=R.drawable.shape_gray_button;
                progress=0;
            }else if (status.equals("1")){
                btnText="认购中";
                backgroundResId=R.drawable.shape_red_button;
                progress=0;
            }else if (status.equals("2")){
                btnText="转让成功";
                backgroundResId=R.drawable.shape_gray_button;
                progress=100;
            }else if (status.equals("3")){ //3
                btnText="转让失败";
                backgroundResId=R.drawable.shape_gray_button;
                progress=0;
            }else{ //4
                btnText="审核不通过";
                backgroundResId=R.drawable.shape_gray_button;
                progress=0;
            }
            holder.mBtnBuy.setText(btnText);
            holder.mBtnBuy.setBackgroundResource(backgroundResId);
            holder.mMyProgressbar.setProgress(progress);
        }


        Glide.with(mFragment)
                .load(Config.URL+data.get(position).getImgUrl())
                .error(R.mipmap.tupian)
                .placeholder(R.mipmap.tupian)
                .into(holder.mIvImg);



    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.iv_img)
        ImageView mIvImg;
        @Bind(R.id.tv_title)
        TextView mTvTitle;
//        @Bind(R.id.tv_number_of_periods)
//        TextView mTvNumberOfPeriods;
        @Bind(R.id.tv_year_rate)
        TextView mTvYearRate;
        @Bind(R.id.tv_year_rate_txt)
        TextView mTvYearRateTxt;
        @Bind(R.id.tv_project_deadline)
        TextView mTvProjectDeadline;
        @Bind(R.id.tv_time_style)
        TextView mTvTimeStyle;
        @Bind(R.id.tv_project_deadline_txt)
        TextView mTvProjectDeadlineTxt;
        @Bind(R.id.tv_project_price_txt)
        TextView mTvProjectPriceTxt;
        @Bind(R.id.tv_project_price)
        TextView mTvProjectPrice;
        @Bind(R.id.tv_project_price_unit)
        TextView mTvProjectPriceUnit;
        @Bind(R.id.btn_buy)
        Button mBtnBuy;
        @Bind(R.id.my_progressbar)
        MyProgressBar mMyProgressbar;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
